﻿package quanlydoanra.baocao.dinhky;

import java.sql.Date;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.List;
import javax.faces.model.SelectItem;
import qldoanra.baocao.theothoigian.TableDisplay;
import dbutil.ConnectDB;
import exportExcel.ExportExcel;
import exportPDF.ExporToPDF;

import utils.DateUtils;
import utils.UtilsOnScopes;

public class BeanBaoCao {
	private String error;
	private String nam;
	private String dinhky;
	private String tieuchi;
	private String thongtin;
	private String lable="Thông tin";
	private String total ="";
	private String pathDownload="";
	private String bieumau="/qldoanra/baocaodinhky/emptyBieuMau.xhtml";
	private List<TableDisplay> list;
	
	/**************************************
	 * Method name		: getYear
	 * Return type		: List<Year>
	 * Decription		:Lay ra danh sach cac nam
	 * Created date		: Jul 13, 2008
	 * Author			: Honglk
	 **************************************/
	private List<Year> getYear(){
		List<Year> list = new ArrayList<Year>();
		int beginYear = DateUtils.LayNamHienTai();
		int yearCurr = 1900;
		while (beginYear  >= yearCurr){
			Year year = new Year();
			year.setValue(String.valueOf(beginYear));
			year.setLable(String.valueOf(beginYear));
			list.add(year);
			beginYear -=1;
		}
		return list;
	}
	
	/**************************************
	 * Method name		: listItemYear
	 * Return type		: SelectItem[]
	 * Decription		:Lay ra cac item select cua nam 
	 * Created date		: Jul 13, 2008
	 * Author			: Honglk
	 **************************************/
	public SelectItem[] listItemYear() {
		List<Year> li = this.getYear();
		SelectItem[] arrItem = new SelectItem[li.size() + 1];
		arrItem[0] = new SelectItem("-1", "---Chọn---");
		for (int i = 0; i < li.size(); i++) {
			Year year = li.get(i);
			arrItem[i + 1] = new SelectItem(year.getValue(), year.getLable());
		}
		return arrItem;
	}
	public SelectItem[] getListItemYear() {
		return this.listItemYear();
	}
	
	
	/**************************************
	 * Method name		: getMonth
	 * Return type		: List<Year>
	 * Decription		:Lay ra danh sach cac thang
	 * Created date		: Jul 13, 2008
	 * Author			: Honglk
	 **************************************/
	
	private List<Month> getMonth() {
		List<Month> list = new ArrayList<Month>();
		int beginMonth = 1;
		// int yearCurr = DateUtils.LayNamHienTai();
		while (beginMonth <= 12) {
			Month month = new Month();
			month.setValue(String.valueOf(beginMonth));
			month.setLable(String.valueOf("Tháng "+beginMonth));
			list.add(month);
			beginMonth += 1;
		}
		Month quy1 = new Month("13", "Quý I");
		Month quy2 = new Month("14", "Quý II");
		Month quy3 = new Month("15", "Quý III");
		Month quy4 = new Month("16", "Quý IV");
		list.add(quy1);
		list.add(quy2);
		list.add(quy3);
		list.add(quy4);
		return list;
	}
	
	/**************************************
	 * Method name		: listItemMonth
	 * Return type		: SelectItem[]
	 * Decription		:Lay ra cac item select cua thang
	 * Created date		: Jul 13, 2008
	 * Author			: Honglk
	 **************************************/
	public SelectItem[] listItemMonth() {
		List<Month> li = this.getMonth();
		SelectItem[] arrItem = new SelectItem[li.size() + 1];
		arrItem[0] = new SelectItem("-1", "---Chọn---");
		for (int i = 0; i < li.size(); i++) {
			Month month = li.get(i);
			arrItem[i + 1] = new SelectItem(month.getValue(), month.getLable());
		}
		return arrItem;
	}
	public SelectItem[] getListItemMonth() {
		return this.listItemMonth();
	}
	
	
	/**************************************
	 * Method name		: getTieuChi
	 * Return type		: List<Month>
	 * Decription		:Lay ra danh sach cac tieu chi
	 * Created date		: Jul 13, 2008
	 * Author			: Honglk
	 **************************************/
	private List<TieuChi> getTieuChi() {
		List<TieuChi> list = new ArrayList<TieuChi>();
		TieuChi tc1 = new TieuChi("1","Cơ quan");
		TieuChi tc2 = new TieuChi("2","Cá nhân");
		TieuChi tc3 = new TieuChi("3","Kinh phí");
		TieuChi tc4 = new TieuChi("4","Mục đích");
		TieuChi tc5 = new TieuChi("5","Nước đến");
		TieuChi tc6 = new TieuChi("6","Đảng viên");
		
		list.add(tc1);
		list.add(tc2);
		list.add(tc3);
		list.add(tc4);
		list.add(tc5);
		list.add(tc6);
		return list;
	}
	
	
	/**************************************
	 * Method name		: listItemTieuChi
	 * Return type		: SelectItem[]
	 * Decription		:Lay ra cac item select cua Tieu chi
	 * Created date		: Jul 13, 2008
	 * Author			: Honglk
	 **************************************/
	public SelectItem[] listItemTieuChi() {
		List<TieuChi> li = this.getTieuChi();
		SelectItem[] arrItem = new SelectItem[li.size() + 1];
		arrItem[0] = new SelectItem("-1", "---Chọn---");
		for (int i = 0; i < li.size(); i++) {
			TieuChi tc = li.get(i);
			arrItem[i + 1] = new SelectItem(tc.getValue(), tc.getLable());
		}
		return arrItem;
	}
	public SelectItem[] getListItemTieuChi() {
		return this.listItemTieuChi();
	}
	
	public String setLableInput(){
		String lable ="";
		String tieuchi = this.tieuchi;
		if(tieuchi.equals("1")){
			this.setLable("Tên cơ quan");
		}
		else if(tieuchi.equals("2")){
			this.setLable("Tên cá nhân");
		}
		else if(tieuchi.equals("3")){
			this.setLable("Kinh phí");
		}
		else if(tieuchi.equals("4")){
			this.setLable("Mục đích");
		}
		else if(tieuchi.equals("5")){
			this.setLable("Nước đến");
		}
		else if(tieuchi.equals("6")){
			this.setLable("Tên ĐV");
		}
		else if(tieuchi.equals("-1")){
			this.setLable("Thông tin");
		}
		return lable;
	}
	
	private String filtData(String nam,String dky){
		String result ="";
		int dkyInt = Integer.parseInt(dky==null?"0":dky);
		switch (dkyInt) {
		case 1:
			result = "DATE_PART('month',D.ngaydi)= '1' " +
				    " AND DATE_PART('year',D.ngaydi)= '" +nam +"'";
			break;
		case 2:
			result = " DATE_PART('month',D.ngaydi)= '2' " +
			" AND DATE_PART('year',D.ngaydi)= '" +nam +"'";
			break;
		case 3:
			result = " DATE_PART('month',D.ngaydi)= '3' " +
			" AND DATE_PART('year',D.ngaydi)= '" +nam +"'";
			break;
		case 4:
			result = " DATE_PART('month',D.ngaydi)= '4' " +
			" AND DATE_PART('year',D.ngaydi)= '" +nam +"'";
			break;
		case 5:
			result = "DATE_PART('month',D.ngaydi)= '5' " +
			" AND DATE_PART('year',D.ngaydi)= '" +nam +"'";
			break;
		case 6:
			result = " DATE_PART('month',D.ngaydi)= '6' " +
			" AND DATE_PART('year',D.ngaydi)= '" +nam +"'";
			break;
		case 7:
			result = " DATE_PART('month',D.ngaydi)= '7' " +
			" AND DATE_PART('year',D.ngaydi)= '" +nam +"'";
			break;
		case 8:
			result = " DATE_PART('month',D.ngaydi)= '8' " +
			" AND DATE_PART('year',D.ngaydi)= '" +nam +"'";
			break;
		case 9:
			result = "DATE_PART('month',D.ngaydi)= '9' " +
			" AND DATE_PART('year',D.ngaydi)= '" +nam +"'";
			break;
		case 10:
			result = " DATE_PART('month',D.ngaydi)= '10' " +
			" AND DATE_PART('year',D.ngaydi)= '" +nam +"'";
			break;
		case 11:
			result = " DATE_PART('month',D.ngaydi)= '11' " +
			" AND DATE_PART('year',D.ngaydi)= '" +nam +"'";
			break;
		case 12:
			result = " DATE_PART('month',D.ngaydi)= '12' " +
			" AND DATE_PART('year',D.ngaydi)= '" +nam +"'";
			break;
		case 13:
			String dateStartStrQuy1 = nam +"-"+ DateUtils.ngayBatDauCuaQuy("13");
			String dateEndStrQuy1 = nam+"-"+ DateUtils.ngayKetThucCuaQuy("13");
			Date dateStartSQLQuy1 = Date.valueOf(dateStartStrQuy1);
			Date dateEndSQLQuy1 = Date.valueOf(dateEndStrQuy1);
			result = "D.ngaydi BETWEEN '" +dateStartSQLQuy1 +
			 					"' AND '" +dateEndSQLQuy1+"'";
			break;
		case 14:
			String dateStartStrQuy2 = nam +"-"+ DateUtils.ngayBatDauCuaQuy("14");
			String dateEndStrQuy2 = nam+"-"+ DateUtils.ngayKetThucCuaQuy("14");
			Date dateStartSQLQuy2 = Date.valueOf(dateStartStrQuy2);
			Date dateEndSQLQuy2 = Date.valueOf(dateEndStrQuy2);
			result = "D.ngaydi BETWEEN '" +dateStartSQLQuy2 +
			"' AND '" +dateEndSQLQuy2+"'";
			
			break;
		case 15:
			String dateStartStrQuy3 = nam +"-"+ DateUtils.ngayBatDauCuaQuy("15");
			String dateEndStrQuy3 = nam+"-"+ DateUtils.ngayKetThucCuaQuy("15");
			Date dateStartSQLQuy3 = Date.valueOf(dateStartStrQuy3);
			Date dateEndSQLQuy3 = Date.valueOf(dateEndStrQuy3);
			result = "D.ngaydi BETWEEN '" +dateStartSQLQuy3 +
			"' AND '" +dateEndSQLQuy3+"'";
			break;
		case 16:
			String dateStartStrQuy4 = nam +"-"+ DateUtils.ngayBatDauCuaQuy("16");
			String dateEndStrQuy4 = nam+"-"+ DateUtils.ngayKetThucCuaQuy("16");
			Date dateStartSQLQuy4 = Date.valueOf(dateStartStrQuy4);
			Date dateEndSQLQuy4 = Date.valueOf(dateEndStrQuy4);
			result = "D.ngaydi BETWEEN '" +dateStartSQLQuy4 +
			"' AND '" +dateEndSQLQuy4+"'";
			break;
		case -1:
			result = "DATE_PART('year',D.ngaydi)='"+nam+"'";
			break;

		default:
			result="DATE_PART('year',D.ngaydi)='"+nam+"'";
			break;
		}
		return result;
	}
	
	private String filtData2(String nam,String dky,String tieuchi,String thongtin){
		String result ="";
		String tempStr = this.filtData(nam, dky);
		int tieuchiInt = Integer.parseInt(tieuchi==null?"0":tieuchi);
		switch (tieuchiInt) {
		case 1: //coquan
			result = tempStr +" AND TRIM(LOWER(D.loaidoan)) LIKE TRIM(LOWER('%"+thongtin+"%')) ";
			break;
		case 2://ca nhan
			result = tempStr +" AND TRIM(LOWER(B.ten)) LIKE TRIM(LOWER('%"+thongtin+"%')) ";
			break;
		case 3://kinh phi
			result = tempStr +" AND D.chiphi ='"+thongtin+"'";
			break;
		case 4://muc dich
			result = tempStr +" AND TRIM(LOWER(E.mucdich)) LIKE TRIM(LOWER('%"+thongtin+"%')) ";
			break;
		case 5://nuoc den
			result = tempStr +" AND TRIM(LOWER(D.nuocden)) LIKE TRIM(LOWER('%"+thongtin+"%')) ";
			break;
		case 6://dang vien
			result = tempStr +" AND B.dangvien ='1' AND (TRIM(LOWER(B.ten)) LIKE TRIM(LOWER('%"+
								(thongtin==null?"-1":thongtin)+"%')) " +
								" OR '" +(thongtin==null?"-1":thongtin)+"'='-1')";
			break;
		case -1:
			result = tempStr;
			break;
			
		default:
			result = tempStr;
		break;
		}
		return result;
	}
	
	
	public String tables() {
		List<TableDisplay> list = new ArrayList<TableDisplay>();
		String cond=this.filtData2(this.nam, this.dinhky,this.tieuchi,this.thongtin);
		String SQL = "select DISTINCT * " +
					  " from hochieu A inner join canhan B on A.cmnd = B.cmnd "+
		              " inner join dsnguoidi C on C.sohc = A.sohc " +
		              " inner join doanra D on D.madoan =C.iddoanra " +
		              " inner join mucdich E on D.idmucdich = E.id " +
		              " inner join quyetdinh F on D.idquyetdinh = F.id " +
		              " inner join (select madoan,sohc,max(G.ngaythaotac) as ngaytrathucte,min(G.ngaythaotac) as ngaynhanhc"
		              +             " from nhatkytranhanhc G group by G.madoan,G.sohc) K "+
		              " on (a.sohc = K.sohc and K.madoan = d.madoan)" +
		              " WHERE " + cond + " AND C.trangthaidi=true AND D.flagdelete = 0";
		System.out.println(SQL);
		ArrayList<HashMap<String, Object>> array = ConnectDB
				.getDataTypeList(SQL);
		try {
			if (array.size() > 0) {
				HashMap<String, Object> hash = new HashMap<String, Object>();
				int stt = 0;
				for (int i = 0; i < array.size(); i++) {
					stt = i + 1;
					hash = (HashMap<String, Object>) array.get(i);
					String ngayve = DateUtils.formatDate(hash.get("ngayve")== null?"":hash.get("ngayve").toString());
					TableDisplay table = new TableDisplay();
					table.setStt(String.valueOf(stt));
					table.setChiphi(hash.get("chiphi")==null?"":hash.get("chiphi").toString());
					table.setChucvu(hash.get("chucvu")== null?"":hash.get("chucvu").toString());
					table.setCmnd(hash.get("cmnd")== null?"":hash.get("cmnd").toString());
					table.setCoquan(hash.get("coquan")==null?"":hash.get("coquan").toString());
					table.setDonvimoi(hash.get("donvimoi")==null?"":hash.get("donvimoi").toString());
					table.setGioitinh(hash.get("gioitinh")==null?"":hash.get("gioitinh").toString());
					table.setLinhvuc(hash.get("linhvuc")==null?"":hash.get("linhvuc").toString());
					table.setLoaidoan(hash.get("loaidoan")==null?"":hash.get("loaidoan").toString());
					table.setMucdich(hash.get("mucdich")==null?"":hash.get("mucdich").toString());
					table.setNamsinh(hash.get("namsinh")==null?"":hash.get("namsinh").toString());
					table.setNgaydi(DateUtils.formatDate(hash.get("ngaydi")==null?"":hash.get("ngaydi").toString()));
					table.setNgayve(ngayve);
					String ngaytrathucte = DateUtils.formatDate(hash.get("ngaytrathucte")==null?"":hash.get("ngaytrathucte").toString());
					String ngaygiao = DateUtils.formatDate(hash.get("ngaynhanhc")==null?"":hash.get("ngaynhanhc").toString());
					if(ngaytrathucte.equalsIgnoreCase(ngaygiao)){
						table.setNgaygiaohc(ngaygiao);
						table.setTrangthainop("Chưa nộp");
						table.setNgaynopthucte("");
					}else{
						table.setTrangthainop("Đã nộp");
						table.setNgaygiaohc(ngaygiao);
						table.setNgaynopthucte(ngaytrathucte);
					}
					table.setNgaykyqd(DateUtils.formatDate(hash.get("ngaykyqd")== null?"":hash.get("ngaykyqd").toString()));
					String ngayquidinhnop = DateUtils.CongTruNgay(ngayve,7);
					table.setNgayquydinhnop(ngayquidinhnop);
					
					table.setNguoikyqd(hash.get("nguoikyqd")==null?"":hash.get("nguoikyqd").toString());
					table.setNuocden(hash.get("nuocden")==null?"":hash.get("nuocden").toString());
					table.setSohc(hash.get("sohc")==null?"":hash.get("sohc").toString());
					table.setSoqd(hash.get("soqd")== null?"":hash.get("soqd").toString());
					table.setTen(hash.get("ten")==null?"":hash.get("ten").toString());
					table.setTrangthai(hash.get("trangthai")==null?"":hash.get("trangthai").toString());
					table.setTrangthaidi(hash.get("trangthaidi")==null?"":hash.get("trangthaidi").toString());
					table.setMadoan(hash.get("madoan")==null?"":hash.get("madoan").toString());
					if(hash.get("dangvien")!=null &&hash.get("dangvien").toString().equals("true")){
						table.setPathImgDangVien("/qldoanra/img/Ok.gif");
					}
					if(hash.get("baocaokq")!=null &&hash.get("baocaokq").toString().equals("true")){
						table.setPathImgBaoCaoKQ("/qldoanra/img/Ok.gif");
						table.setBaocaokq("Có");
					}
					else if (hash.get("baocaokq").toString().equals("false")){
						table.setBaocaokq("Không");
					}
					table.setLoaihc(hash.get("loaihc")==null?"":hash.get("loaihc").toString());
					list.add(table);
//					this.setBieumau("/qldoanra/baocaodinhky/bieumau.xhtml");
				}
			}else{
				list = new ArrayList<TableDisplay>();
			}
			this.setList(list);
			String totalAlert = this.tong(list);
			this.setTotal(totalAlert);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "";
	}
	
	private String tong(List<TableDisplay> list) {
		String result = "";
		int tieuChiID = Integer.parseInt(this.tieuchi);
		HashSet<String> set = new HashSet<String>();
		if (list != null && list.size() > 0) {
			switch (tieuChiID) {
			case 1:
				for (TableDisplay t : list) {
					set.add(t.getMadoan());
				}
				result = ("Tổng số đoàn : " +String.valueOf(set.size()));
				break;
			case 2:
				result = ("Tổng số người : " +String.valueOf(list.size()));
				break;
			case 3:
				int totalCost = 0;
				for (TableDisplay t : list) {
					totalCost += Integer.parseInt(t.getChiphi());
				}
				result = ("Tổng kinh phí : " +String.valueOf(totalCost));
				break;
			case 4:
				for (TableDisplay t : list) {
					set.add(t.getMadoan());
				}
				result = ("Tổng số đoàn : " +String.valueOf(set.size()));
				break;
			case 5:
				for (TableDisplay t : list) {
					set.add(t.getMadoan());
				}
				result = ("Tổng số đoàn : " +String.valueOf(set.size()));
				break;
			case 6:
				result = ("Tổng số đảng viên : " +String.valueOf(list.size()));
				break;
			case -1:
				for (TableDisplay t : list) {
					set.add(t.getMadoan());
				}
				result = ("Tổng số đoàn : " +String.valueOf(set.size()));
				break;
			default:
				for (TableDisplay t : list) {
					set.add(t.getMadoan());
				}
			result = ("Tổng số đoàn : " +String.valueOf(set.size()));
			break;
			}
		}
		return result;
	}
	
	public boolean checkError(){
		if(this.nam == null || this.nam.equals("-1")){
			this.setError("Bạn chưa chọn năm !");
			return false;
		}else 
			if(!(this.tieuchi.equals("-1")) && !(this.tieuchi.equals("6"))){
			   if(this.thongtin == null || this.thongtin.equals("")){
				   this.setError("Bạn chưa nhập " +this.getLable()+ "!");
				   return false;
			   }
			   else if(this.tieuchi.equals("3")){
				   try{
					   Integer.parseInt(this.thongtin);
				   }catch(Exception e){
					   this.setError("Kinh phí phải là số !");
					   return false;
				   }
			   }
		}
		return true;
	}
	
	public String view(){
		this.setError("");
		if(this.checkError() == false){
			return "";
		}
		else {
		this.tables();
		  if(this.list.size() > 0){
		     this.setBieumau("/qldoanra/baocaodinhky/bieumau.xhtml");
		  }else{
			 this.setError("Không có dữ liệu !");
//			 return "";
		  }
		}
		
		return "okBaoCaoDinhKy";
	}
	
	public String reset() {
		UtilsOnScopes.getSession().removeAttribute("beanBaoCao");
		return "okBaoCaoDinhKy";
	}
	
	
	public String getError() {
		return error;
	}

	public void setError(String error) {
		this.error = error;
	}

	public String getLable() {
		return lable;
	}

	public void setLable(String lable) {
		this.lable = lable;
	}

	public String getNam() {
		return nam;
	}
	public void setNam(String nam) {
		this.nam = nam;
	}
	public String getDinhky() {
		return dinhky;
	}
	public void setDinhky(String dinhky) {
		this.dinhky = dinhky;
	}
	public String getTieuchi() {
		return tieuchi;
	}
	public void setTieuchi(String tieuchi) {
		this.tieuchi = tieuchi;
	}
	public String getThongtin() {
		return thongtin;
	}
	public void setThongtin(String thongtin) {
		this.thongtin = thongtin;
	}

	public List<TableDisplay> getList() {
		return list;
	}

	public void setList(List<TableDisplay> list) {
		this.list = list;
	}

	public String getTotal() {
		return total;
	}

	public void setTotal(String total) {
		this.total = total;
	}
	
	
	public String getPathDownload() {
		return pathDownload;
	}

	public void setPathDownload(String pathDownload) {
		this.pathDownload = pathDownload;
	}

	public String getBieumau() {
		return bieumau;
	}

	public void setBieumau(String bieumau) {
		this.bieumau = bieumau;
	}
	
	public String setThoiGian(){
		String result ="";
		if(this.dinhky.equals("-1")){
			result ="";
		}else {
			if(this.dinhky.equals("13") ||this.dinhky.equals("14") ||
					this.dinhky.equals("15") ||this.dinhky.equals("16")){
				int dinhKyInt = Integer.parseInt(this.dinhky);
				switch (dinhKyInt) {
				case 13: 
					result ="Qúy I";
					break;
				case 14: 
					result ="Qúy II";
					break;
				case 15: 
					result ="Qúy III";
					break;
				case 16: 
					result ="Qúy IV";
					break;

				default:
					result ="";
					break;
				}
			}else{
				result ="Tháng "+this.dinhky;
			}
		}
		return result;
	}
	

	/**************************************
	 * Method name		: export
	 * Return type		: String
	 * Decription		:Xuat ra file Excel
	 * Created date		: Jul 26, 2008
	 * Author			: Honglk
	 * Modified			: Phonglt [sua pathDownload]
	 **************************************/
	public String export() {
		this.setError("");
		if(this.checkError()== false){
			return "";
		}
		String cond=this.filtData2(this.nam, this.dinhky,this.tieuchi,this.thongtin);

		String SQL = "select DISTINCT * " +
					" from hochieu A inner join canhan B on A.cmnd = B.cmnd "+
					" inner join dsnguoidi C on C.cmnd = B.cmnd " +
					" inner join doanra D on D.madoan =C.iddoanra " +
					" inner join mucdich E on D.idmucdich = E.id " +
					" inner join quyetdinh F on D.idquyetdinh = F.id " +
					" inner join (select madoan,sohc,max(G.ngaythaotac) as ngaytrathucte,min(G.ngaythaotac) as ngaynhanhc"
					+             " from nhatkytranhanhc G group by G.madoan,G.sohc) K "+
					" on (a.sohc = K.sohc and K.madoan = d.madoan)" +
					" WHERE " + cond + " AND C.trangthaidi=true AND D.flagdelete = 0";
		System.out.println(SQL);
		
		ArrayList<HashMap<String, Object>> listObject = ConnectDB
				.getDataTypeList(SQL);
		if(listObject == null || listObject.size() > 0){
			//Header
		Hashtable<String, String> heading = new Hashtable<String, String>();	
			heading.put("THOIGIAN", this.setThoiGian());
			heading.put("NAM", this.nam);
			//Footer
			Hashtable<String, String> ending = new Hashtable<String, String>();	
			ending.put("NGAY", String.valueOf(DateUtils.LayNgayHienTai()));
			ending.put("THANG", String.valueOf(DateUtils.LayThangHienTai()));
			ending.put("NAM", String.valueOf(DateUtils.LayNamHienTai()));
		ExportExcel.exportJExcel_HaveGroup("quanlydoanra_template", "baocaodinhky.xml",
				"exp_quanlydoanra", listObject, UtilsOnScopes.getRequest(), 
				heading, ending);
		this.setPathDownload( ExportExcel.pathDownload);
		this.setBieumau("/qldoanra/baocaodinhky/viewExportExcel.xhtml");
		}
		else{
			this.setError("Không có dữ liệu !");
		}
		return "okBaoCaoDinhKy";
	}


      /**************************************
     * Method name		: exportPDF
     * Return type		: String
     * Description		:xuat ra file PDF
     * Created date		: Aug 23, 2008
     * Author			: Phonglt
     **************************************/
    public String exportPDF(){
    	  this.setError("");
    	  if (this.checkError() == false) {
			return "";
		} else {
			this.tables();
			List<TableDisplay> listData = this.getList();
			if (listData.size() > 0) {
				ExporToPDF<TableDisplay> exportPDF = new ExporToPDF<TableDisplay>();
				HashMap<String, String> parameter = new HashMap<String, String>();
				parameter.put("THOIGIAN", this.setThoiGian());
				parameter.put("NAM", this.nam);
				exportPDF.exportToPDF("quanlydoanra_template", "baocaodinhky",
						"exp_quanlydoanra", parameter, "baocaodinhky", listData);
				this.setPathDownload(exportPDF.getPathDownload());
				this.setBieumau("/qldoanra/baocaodinhky/viewExportExcel.xhtml");
			} else {
				this.setError("Không có dữ liệu !");
			}
		}
		return "okBaoCaoDinhKy";
	}

}
